package cn.haona.game.simb.wap.interceptor;

import java.util.Iterator;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.util.ValueStack;


/**
 * 从ActionContext中取得参数并添加到request对象中
 * @author Administrator
 *
 */
public class AddParamToRequestInterceptor extends AbstractInterceptor
{

	@Override
	public String intercept(ActionInvocation action) throws Exception
	{
		//结果
		String result=action.invoke();
		
		//得到Action上下文对象
		ActionContext context = action.getInvocationContext();
		System.out.println("context="+context);
		//得到request对象
		HttpServletRequest request = 
//			ServletActionContext.getRequest();
			(HttpServletRequest) context.get(org.apache.struts2.StrutsStatics.HTTP_REQUEST); 

		//得到它所有的参数
		Map params =context.getValueStack().getExprOverrides();
		ValueStack valueStack=context.getValueStack();
//		Iterator<Object> itera=valueStack.getRoot().iterator();
//		while(itera.hasNext())
//		{
//			ActionSupport as=null;
//			as.
//			Object obj=itera.next();
//			System.out.println(obj);
//		}
//		String notice=context.getValueStack().findString("notice");
//		Iterator<Object> itera=params.entrySet().iterator();
//		//逐个把参数赋予request中
//		while(itera.hasNext())
//		{
//			Map.Entry entry = (Map.Entry) itera.next();
//			String key=(String)entry.getKey();
//			Object value=entry.getValue();
//			if(request.getAttribute(key)==null)
//			{
//				request.setAttribute(key, value);
//			}
//			
//		}
		
		return result;
	}

}
